// by Xeno
#define THIS_FILE "fn_sidefactory2.sqf"
#include "x_setup.sqf"
private ["_buildings", "_down"];
if !(call FUNC(checkSHC)) exitWith {};
__TRACE_1("","_this")

_buildings = _this;
if (count _buildings > 3) then {
	_buildings = [_buildings select 0,_buildings select 1,_buildings select 2];
};
_down = 0;

#ifdef __TT__
GVAR(sm_points_blufor) = 0;
GVAR(sm_points_opfor) = 0;
{
	_x addEventHandler ["killed", {_this call FUNC(AddSMPoints)}];
} foreach _buildings;
#endif

while {(_down < count _buildings)} do {
	call FUNC(mpcheck);
	_down = {!alive _x} count _buildings;
	sleep 5.321;
};

#ifndef __TT__
GVAR(sm_winner) = 2;
#else
if (GVAR(sm_points_blufor) > GVAR(sm_points_opfor)) then {
	GVAR(sm_winner) = 2;
} else {
	if (GVAR(sm_points_opfor) > GVAR(sm_points_blufor)) then {
		GVAR(sm_winner) = 1;
	} else {
		if (GVAR(sm_points_opfor) == GVAR(sm_points_blufor)) then {
			GVAR(sm_winner) = 123;
		};
	};
};
#endif
GVAR(sm_resolved) = true;
if (GVAR(IS_HC_CLIENT)) then {
	[QGVAR(sm_var), GVAR(sm_winner)] call FUNC(NetCallEventCTS);
};